<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="cn.java71.dao.*,cn.java71.entity.*,cn.java71.util.*" %>
<%@ page import="cn.java71.service.*" %>
<%@ page import="java.util.List" %>
<html>
<head>
    <title>显示首页的学生</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
           $("#jump").keypress(function (event) {
               //alert($(this).attr("max"));
               if(event.keyCode==13){
                   if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                       alert("超了");
                       return false;
                   }
                   window.location.href="students.jsp?p="+$(this).val()+"&sname="+$("#sname").val();
               }
           }).blur(function () {
               if(parseInt($(this).val())>parseInt($(this).attr("max"))){
                   alert("超了");
                   return false;
               }

               window.location.href="students.jsp?p="+$(this).val()+"&sname="+$("#sname").val();
           });
        });
    </script>
</head>
<body>
<%--<%
    out.print(session.getId()+"<br/>");
    out.print(session.getLastAccessedTime()+"<br/>");
    out.print(session.getMaxInactiveInterval()+"<br/>");
    //String name=(String)session.getAttribute("LOGIN_USER");
%>--%>
<%--<h1>欢迎你，<%=name%></h1>--%>
<%--<%@include file="checkLogin.jsp"%>--%>

<%
    int p=1;
    try {
        p = Integer.parseInt(request.getParameter("p"));
    }catch (Exception e){}
    int pageSize=20;
    String sname=request.getParameter("sname");
    sname=sname==null?"":sname;
    StudentService studentService=new StudentService();
    Page<Student> students = studentService.search(p, pageSize, sname, null, null);

%>
<form action="students.jsp">
    <input type="search" id="sname" name="sname" value="<%=sname%>" placeholder="姓名"/>
    <input type="search" id="telephone" name="telephone" value="" placeholder="telephone"/>
    <input type="search" id="qq" name="qq" value="" placeholder="qq"/>
    <input type="submit" value="查找"/>
</form>
<%--<h1>
    <%
        out.print(",当前时间:"+request.getAttribute("loginTime"));
        out.print("，当前用户:"+request.getParameter("userName"));
    %>
</h1>--%>
<table border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>手机号</th>
        <th>入学日期</th>
        <th>操作</th>
    </tr>
    <%
        for(Student stu:students.getDatas()){
    %>
    <tr>
        <td><%=stu.getStuno()%></td>
        <td><%=stu.getSname()%></td>
        <td><%=stu.getTelephone()%></td>
        <td><%=stu.getEnterdate()%></td>
        <td>
            <a onclick="return confirm('真的要删除<%=stu.getSname()%>？')"
               href="delStudent.jsp?stuno=<%=stu.getStuno()%>">删除</a>
            <a href="studentUpdate.jsp?stuno=<%=stu.getStuno()%>">修改</a>
        </td>
    </tr>

    <%}%>
</table>
</ul>
<p align="center">
    <a href="students.jsp?p=1&sname=<%=sname%>">首页</a>
    <% if(students.getPageNo()>1){%>
    <a href="students.jsp?p=<%=p-1%>&sname=<%=sname%>">上一页</a>
    <%}%>
    <input type="number" min="1" max="<%=students.getTotalPages()%>" name="p" id="jump" size="4" value="<%=p%>" style="width: 50px"/>
    <%
        if(students.getPageNo()<students.getTotalPages()){
    %>
    <a href="students.jsp?p=<%=p+1%>&sname=<%=sname%>">下一页</a>
    <%}%>
    <a href="students.jsp?p=<%=students.getTotalPages()%>&sname=<%=sname%>">末页</a>
</p>
</body>
</html>
